﻿@model IEnumerable<Domain.Entities.WebManageRoles>
@{
    ViewBag.Title = "Index";
    Layout = "~/views/shared/_LayoutBasic.cshtml";
}
<h2>
    Index</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
        </th>
        <th>
            ManageRoleID
        </th>
        <th>
            RoleName
        </th>
        <th>
            DepartmentID
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                <input type="checkbox"  value="@item.ManageRoleID" />
                @Html.Hidden("ManageRoleID", item.ManageRoleID)
                @Html.Hidden("RoleName", item.RoleName)
            </td>
            <td>
                @item.ManageRoleID
            </td>
            <td>
                @item.RoleName
            </td>
            <td>
                @item.DepartmentID
            </td>
        </tr>
    }
    <tfoot>
        <tr>
            <td colspan="4">
                <input type="button" value="选择" id="selectBtn" />
            </td>
        </tr>
    </tfoot>
</table>
<script type="text/javascript">
    $("#selectBtn").click(function () {
        if ($("input[type=checkbox]:checked").length === 0) {
            return false;
        }

        var id = '', name = '';
        $("input[type=checkbox]:checked").each(function (i, o) {
            id += $(o).nextAll("input[name=ManageRoleID]").val() + ",";
            name += $(o).nextAll("input[name=RoleName]").val() + ",";
        });

        $("#RoleName", window.parent.document).val(name);
        $("#ManageRoleID", window.parent.document).val(id);
        $(".boxy-wrapper", window.parent.document).hide();
    });
</script>
